Read content of a skip list

Hi,

 

I have this code:

Module myCurrentModule

//Nur das erste Modul aus der Skip-Liste auslesen, damit die Iteration gestartet werden kann.

 

if(find(mySkipList, 1, myCurrentModuleSkip))

{

if(read(fullName(myCurrentModuleSkip)) == Module)

{

myCurrentModule = read(fullName(myCurrentModuleSkip))

}

else

{

print "Kein Modul!"

}

}

 

My question now is: How can I check if a module is in "myCurrentModuleSkip"? I will check this in the second if-statement.


tobi_mehrl - Mon Jun 01 04:31:13 EDT 2015

Re: Read content of a skip list
Wolfgang Uhr - Mon Jun 01 05:18:35 EDT 2015

Hi

// you want to check if the module exists in the skip

bool

 

 

hasModuleInList(Skip skpWork, string sModuleID) {

 

Module mdlWork;

 

for mdlWork in skpWork do {

 

if (uniqueID(mdlWork) == sModuleID) { return(true) }

}

 

return(false);

}

 

// you want to get the module

Module

 

 

getModuleFromList(Skip skpWork, string sModuleID) {

 

Module mdlWork;

 

for mdlWork in skpWork do {

 

if (uniqueID(mdlWork) == sModuleID) { return(mdlWork) }

}

 

return(null);

}

Re: Read content of a skip list
Wolfgang Uhr - Mon Jun 01 05:19:36 EDT 2015

Wolfgang Uhr - Mon Jun 01 05:18:35 EDT 2015

Hi

// you want to check if the module exists in the skip

bool

 

 

hasModuleInList(Skip skpWork, string sModuleID) {

 

Module mdlWork;

 

for mdlWork in skpWork do {

 

if (uniqueID(mdlWork) == sModuleID) { return(true) }

}

 

return(false);

}

 

// you want to get the module

Module

 

 

getModuleFromList(Skip skpWork, string sModuleID) {

 

Module mdlWork;

 

for mdlWork in skpWork do {

 

if (uniqueID(mdlWork) == sModuleID) { return(mdlWork) }

}

 

return(null);

}

Wonderfull, IBM has changed a bad forum to a worst.

Re: Read content of a skip list
tobi_mehrl - Mon Jun 01 05:40:28 EDT 2015

Hi Wolfgang,

sorry, but was I mean is, that I don't want to check If a specific module is in the skip list. What I want to do is, that I will check, if the first element of the skip list is from type "module". Do you understand what I mean?

What you in your code do is to test, if in the skip is a module which a specific name; which specific name is assigned in sModuleID, I think.

Re: Read content of a skip list
Wolfgang Uhr - Mon Jun 01 06:20:06 EDT 2015

tobi_mehrl - Mon Jun 01 05:40:28 EDT 2015

Hi Wolfgang,

sorry, but was I mean is, that I don't want to check If a specific module is in the skip list. What I want to do is, that I will check, if the first element of the skip list is from type "module". Do you understand what I mean?

What you in your code do is to test, if in the skip is a module which a specific name; which specific name is assigned in sModuleID, I think.

Hi Tobi

If you want to find the first entry, create a skip loop inside a function and return using the first hit from the loop.

But if you want to find out of the first entry is a module or an object, forget it. DXL will provide the datatype unless a crash - not an error but a real crash occurs. And of course, thats the thing, type casting has been made for. You have to know the datatye you are dealing with.

Best regards

Wolfgang

Re: Read content of a skip list
tobi_mehrl - Mon Jun 01 06:37:25 EDT 2015

quote: "And of course, thats the thing, type casting has been made for."

 

What do you mean by saying this?

Re: Read content of a skip list
Wolfgang Uhr - Mon Jun 01 06:41:54 EDT 2015

tobi_mehrl - Mon Jun 01 06:37:25 EDT 2015

quote: "And of course, thats the thing, type casting has been made for."

 

What do you mean by saying this?

You have to know the datatype you are dealing with.

Re: Read content of a skip list
llandale - Mon Jun 01 19:35:06 EDT 2015

tobi_mehrl - Mon Jun 01 06:37:25 EDT 2015

quote: "And of course, thats the thing, type casting has been made for."

 

What do you mean by saying this?

It means you need to know what type is in the Skip BEFORE you try to pull it out.  If it is indeed an Object and you put it into a Module handle you can expect quick destruction of your run time environment the first time you use that Module handle.

I suggest you are making a big conceptual mistake in your script design if you NEED to put both Objects and Modules into the same Skip, with an "int" sequencer KEY.

But you may have your cake and eat it too if you cleverly decide that all "Module" handles in the Skip have an odd 'int' Key; whereas all "Object" handles have an even 'int' Key.

  • int g_Sequencer = 0
  • Skip g_skpConfused = create()
  • void put(Module m)
  • {  if g_Sequencer is even then g_Sequencer++   // make it the next odd number
  •    put(skpConfused, g_Sequencer++, m)
  • }
  • void put(Object o)
  • {  if g_Sequencer is odd then g_Sequencer++  // make it the next even number
  •    put(skpConfused, g_Sequencer++, o)
  • }
  • Object o
  • int Index
  • for o in g_skpConfused do
  • {  Index = (int key g_skpConfused)
  •    if (Index is odd)     then continue   // Oops, a module
  •     deal with o
  • }
  • Module m
  • for m in g_skpConfused do
  • {  Index = (int key g_skpConfused)
  •    if (index is even)   then continue // Oops, an Object
  •    deal with m
  • }

-Louie

Re: Read content of a skip list
pommCannelle - Mon Jun 22 08:40:39 EDT 2015

llandale - Mon Jun 01 19:35:06 EDT 2015

It means you need to know what type is in the Skip BEFORE you try to pull it out.  If it is indeed an Object and you put it into a Module handle you can expect quick destruction of your run time environment the first time you use that Module handle.

I suggest you are making a big conceptual mistake in your script design if you NEED to put both Objects and Modules into the same Skip, with an "int" sequencer KEY.

But you may have your cake and eat it too if you cleverly decide that all "Module" handles in the Skip have an odd 'int' Key; whereas all "Object" handles have an even 'int' Key.

  • int g_Sequencer = 0
  • Skip g_skpConfused = create()
  • void put(Module m)
  • {  if g_Sequencer is even then g_Sequencer++   // make it the next odd number
  •    put(skpConfused, g_Sequencer++, m)
  • }
  • void put(Object o)
  • {  if g_Sequencer is odd then g_Sequencer++  // make it the next even number
  •    put(skpConfused, g_Sequencer++, o)
  • }
  • Object o
  • int Index
  • for o in g_skpConfused do
  • {  Index = (int key g_skpConfused)
  •    if (Index is odd)     then continue   // Oops, a module
  •     deal with o
  • }
  • Module m
  • for m in g_skpConfused do
  • {  Index = (int key g_skpConfused)
  •    if (index is even)   then continue // Oops, an Object
  •    deal with m
  • }

-Louie

( Have you tried to indicate the type when you add data in the skip ... Here a simple example with string and int ... but you can use the types you need to ;)

[code]

DxlObject obj

// skip list with integer as key, dxl object as data
// so the data itsefl is abble to embed his type ...

Skip test = create()

obj = new()
obj->"type" = "string"
obj->"data" = "this is a string"

put(test, 1, obj)

obj = new()
obj->"type" = "integer"
obj->"data" = 123456789

put(test, 2, obj)

// get data with the proper type - 0.0
string obj_type = ""
int tmp_integer = null
string tmp_string = null

for obj in test do {
    obj_type = (string obj->"type")
    if ( obj_type"" == "string" ) {
        tmp_string = (string obj->"data")
        print tmp_string "\n" 
        continue
    }
    if ( obj_type"" == "integer" ) {
        tmp_integer = (int obj->"data")
        print tmp_integer "\n"
    }
}

// get data  - version 0.1

int tmp_integer = null
string tmp_string = null

string getdata(DxlObject obj) {
    string obj_type = (string obj->"type")
    if ( obj_type"" != "string" ) return null
    string rez = (string obj->"data")
    return rez
}

int getdata(DxlObject obj) {
    string obj_type = (string obj->"type")
    if ( obj_type"" != "integer" ) return null
    int rez = (int obj->"data")
    return rez
}

for obj in test do {
    tmp_integer = getdata(obj)
    tmp_string = getdata(obj)
    if ( ! null tmp_string ) print tmp_string "\n"
    if ( ! null tmp_integer ) print tmp_integer "\n"
}

// clean memory
for obj in test do delete obj
delete test

[/code]

Re: Read content of a skip list
Wolfgang Uhr - Mon Jun 22 10:37:15 EDT 2015

pommCannelle - Mon Jun 22 08:40:39 EDT 2015

( Have you tried to indicate the type when you add data in the skip ... Here a simple example with string and int ... but you can use the types you need to ;)

[code]

DxlObject obj

// skip list with integer as key, dxl object as data
// so the data itsefl is abble to embed his type ...

Skip test = create()

obj = new()
obj->"type" = "string"
obj->"data" = "this is a string"

put(test, 1, obj)

obj = new()
obj->"type" = "integer"
obj->"data" = 123456789

put(test, 2, obj)

// get data with the proper type - 0.0
string obj_type = ""
int tmp_integer = null
string tmp_string = null

for obj in test do {
    obj_type = (string obj->"type")
    if ( obj_type"" == "string" ) {
        tmp_string = (string obj->"data")
        print tmp_string "\n" 
        continue
    }
    if ( obj_type"" == "integer" ) {
        tmp_integer = (int obj->"data")
        print tmp_integer "\n"
    }
}

// get data  - version 0.1

int tmp_integer = null
string tmp_string = null

string getdata(DxlObject obj) {
    string obj_type = (string obj->"type")
    if ( obj_type"" != "string" ) return null
    string rez = (string obj->"data")
    return rez
}

int getdata(DxlObject obj) {
    string obj_type = (string obj->"type")
    if ( obj_type"" != "integer" ) return null
    int rez = (int obj->"data")
    return rez
}

for obj in test do {
    tmp_integer = getdata(obj)
    tmp_string = getdata(obj)
    if ( ! null tmp_string ) print tmp_string "\n"
    if ( ! null tmp_integer ) print tmp_integer "\n"
}

// clean memory
for obj in test do delete obj
delete test

[/code]

> Have you tried to indicate the type when you add data in the skip ... Here a simple example with string and int ... but you can use the types you need to

It is much more simple to use a prefix in the variable.

int iSomeInt = 12:

string sSomeString = "some words"

Object objSomeObject = ...

put(mySkip, "iSomeInt ", iSomeInt);

put(mySkip, "sSomeString", sSomeString);

put(mySkip, "objSomeObject", objSomeObject);

If your loop runs through that list, your prefix will tell you the type.

Best regards

Wolfgang